package rpg.client.model;

import java.util.Collections;
import java.util.List;

import rpg.client.model.Actor.Gender;

public final class GameEvent {
    public enum Type {
        NOTHING, CHANGE_MAP, CHANGE_POSITION, CHAT_INSTRUCTION, RENDER_CHAT, OBJECT_ACTIVATE, OBJECT_DEACTIVATE, PLAYER_ANIMATE, NPC_MOVE, GENDER_CHANGE;
    }

    public static final List<GameEvent> EMPTY_LIST = Collections.emptyList();

    public static GameEvent changeLocation(Position newPosition, Position oldPosition, Facing f) {
        return new GameEvent((newPosition.getMapID().equals(oldPosition.getMapID()) ? Type.CHANGE_POSITION
                : Type.CHANGE_MAP), newPosition, "", "", f);
    }

    public static GameEvent chatInstruction(String storyID, String chatID) {
        return new GameEvent(Type.CHAT_INSTRUCTION, Position.VOID, storyID, chatID, Facing.NULL);
    }

    public static GameEvent npcMoved(String npcID, Position toPosition, Facing facing) {
        return new GameEvent(Type.NPC_MOVE, toPosition, "", npcID, facing);
    }

    public static GameEvent objectActivated(String gameObjectID) {
        return new GameEvent(Type.OBJECT_ACTIVATE, Position.VOID, "", gameObjectID, Facing.NULL);
    }

    public static GameEvent objectDeactivated(String gameObjectID) {
        return new GameEvent(Type.OBJECT_DEACTIVATE, Position.VOID, "", gameObjectID, Facing.NULL);
    }

    public static GameEvent renderChat(String storyID, String chatID) {
        return new GameEvent(Type.RENDER_CHAT, Position.VOID, storyID, chatID, Facing.NULL);
    }

    private final Facing facing;

    private final Position position;
    private final Type type;

    private final String storyID;
    private final String id;

    public static final GameEvent NULL = new GameEvent(Type.NOTHING, Position.VOID, "", "", Facing.NULL);

    public static GameEvent genderChange(String actorID, Gender g) {
        return new GameEvent(Type.GENDER_CHANGE, Position.VOID, "", g.name(), Facing.NULL);
    }

    private GameEvent(Type type, Position pos, String storyID, String id, Facing facing) {
        super();
        this.type = type;
        this.position = pos;
        this.storyID = storyID;
        this.id = id;
        this.facing = facing;
    }

    public Facing getFacing() {
        return facing;
    }

    public String getId() {
        return id;
    }

    public Position getPosition() {
        return position;
    }

    public String getStoryID() {
        return storyID;
    }

    public Type getType() {
        return type;
    }

    @Override
    public String toString() {
        return "GameEvent: " + getType();
    }
}
